import AbstractField from '@/components/hhd/design/FormDesigner/field/comps/AbstractField';
import {createDefaultFieldElement} from '@/utils/FormDesignUtils';
import {createField} from '@/components/hhd/design/FormDesigner/types';
import {guid, isEmpty} from '@/utils';
import $ from 'jquery';
import {message} from "ant-design-vue";

export default class Departs extends AbstractField {
    getFieldComponentTitle() {
        return '选多部门';
    }

    getFieldComponentName() {
        return 'departs';
    }

    getDefaultConfig() {
        return new Promise((resolve) => {
            let field = createField();
            field.id = guid();
            field.component = 'departs'
            field.fieldName = '选多部门'
            field.label = '选多部门'
            field.placeholder = '请选择部门'
            resolve(field);
        });
    }

    checkField(field) {
        if (super.checkField(field)) {
            if (isEmpty(field.dict)) {
                message.error(field.label+' 数据可选范围不能为空')
                return false
            } else
                return true
        } else {
            return false
        }
    }

    createFieldElement() {
        return new Promise((resolve) => {
            resolve(this.createDefaultFieldElement());
        })
    }

    setFieldTitle(el, fieldConfig) {
        $(el).find('span[data-role=field-title]').html(fieldConfig.label);
    }

    createDefaultFieldElement() {
        let res = createDefaultFieldElement();
        res.innerHTML = '<span data-role="field-title">选多部门</span>'
        return res;
    }
};
